package com.gh.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gh.common.result.R;
import com.gh.entity.UserInfo;
import com.gh.query.UserInfoQuery;
import com.gh.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Eric
 * @Date 2021/9/23 23:10
 * @Version 1.0
 */
@Api(tags = "会员管理接口")
@RestController
@Slf4j
@RequestMapping("/admin/core/userInfo")
@RequiredArgsConstructor
public class AdminUserInfoController {

    private final UserInfoService userInfoService;

    @ApiModelProperty(value = "获取会员分页列表")
    @PostMapping("listPage/{page}/{limit}")
    public R listPage(@ApiParam(value = "查询对象", required = false)
                      @RequestBody UserInfoQuery userInfoQuery,
                      @ApiParam(value = "当前页码", required = true)
                      @PathVariable Long page,
                      @ApiParam(value = "每页记录数", required = true)
                      @PathVariable Long limit) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectListPage(userInfoQuery, pageParam);
        return R.ok().data("pageModel", pageModel);
    }

    @ApiModelProperty(value = "锁定和解锁")
    @PutMapping("lock/{id}/{status}")
    public R lock(@ApiParam(value = "用户id", required = true)
                  @PathVariable Long id,
                  @ApiParam(value = "状态(0锁定，1正常)", required = true)
                  @PathVariable Integer status) {
        userInfoService.lock(id, status);
        return R.ok().message(status == 1 ? "解锁成功" : "已锁定");
    }
}
